{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0b4f9658",
   "metadata": {},
   "source": [
    "## 百度api接口作业尝试"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c06ceb57",
   "metadata": {},
   "source": [
    "### 开发理念：\n",
    "> 1. 借助百度识图中的地标识别，建立一个经过地打卡趣味产品\n",
    "> 2. 实现用户拍照上传打卡人生轨迹，记录一生/一段时间走过的人生轨迹\n",
    "### 用户需求：\n",
    "> 1. 快节奏生活让人们没能注意到生活中的细节，拍照写下回忆录\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6972ce99",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.d5e7bcfdfed9531a2f4138256d6d5b35.2592000.1652273360.282335-25904777'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests \n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=AblvqrCFNWG0IcGTVZwkTYOi&client_secret=e5MRWHNpOtoVicw1DrDjuTA3AGD2wB0V'\n",
    "#准备URL参数\n",
    "payload = {\n",
    "    'grant_type':'client_credentials',\n",
    "    'client_id':'AblvqrCFNWG0IcGTVZwkTYOi',\n",
    "    'client_secret':'e5MRWHNpOtoVicw1DrDjuTA3AGD2wB0V'\n",
    "}\n",
    "response = requests.get(host,params=payload)\n",
    "token = response.json()[\"access_token\"]\n",
    "token"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc74e992",
   "metadata": {},
   "source": [
    "#### 国内景点打卡"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3d8862e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': {'landmark': '广州塔'}, 'log_id': 1513499451448387959}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "地标识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/landmark\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('guangzhouta.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "a\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b03e057",
   "metadata": {},
   "source": [
    "#### 国外打卡"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "51946bd5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': {'landmark': '埃菲尔铁塔'}, 'log_id': 1513479630061809597}\n"
     ]
    }
   ],
   "source": [
    "f = open('aifeier.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img,\n",
    "         \"access_token\":token\n",
    "         }\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10e5f094",
   "metadata": {},
   "source": [
    "# 打卡功能仍未实现，亟待开发"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dde5b512",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b2dca16f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
